function [txn] = demapper(inp,width,height)
    [ncol,nrow] = size(inp);
    assert((ncol*nrow) == (width*height*4));
    txn = zeros(height,width);
    bin_inp = zeros(1,8,'uint8'); %#ok<NASGU>
 for index = 1:floor(numel(inp)/4)
 %    bin_inp = de2bi(inp(index),8);
%     comp_no1 = round(inp(4*((index) - 1) + 1));
%     comp_no2 = round(inp(4*((index) - 1) + 2));
%     comp_no3 = round(inp(4*((index) - 1) + 3));
%     comp_no4 = round(inp(4*((index) - 1) + 4));
    
    comp_no1 = alternatedemap(round(inp(4*((index) - 1) + 1)));
    comp_no2 = alternatedemap(round(inp(4*((index) - 1) + 2)));
    comp_no3 = alternatedemap(round(inp(4*((index) - 1) + 3)));
    comp_no4 = alternatedemap(round(inp(4*((index) - 1) + 4)));


    bin_inp(1) = (real(comp_no1)*sqrt(2)+1)/2;
    bin_inp(3) = (real(comp_no2)*sqrt(2)+1)/2;
    bin_inp(5) = (real(comp_no3)*sqrt(2)+1)/2;
    bin_inp(7) = (real(comp_no4)*sqrt(2)+1)/2;
    
    bin_inp(2) = (imag(comp_no1)*sqrt(2)+1)/2;
    bin_inp(4) = (imag(comp_no2)*sqrt(2)+1)/2;
    bin_inp(6) = (imag(comp_no3)*sqrt(2)+1)/2;
    bin_inp(8) = (imag(comp_no4)*sqrt(2)+1)/2;
%    txn(4*((index) - 1) + 1) = complex(((2*double(bin_inp(1)) - 1)/sqrt(2)),((2*double(bin_inp(2)) - 1)/sqrt(2)));
%    txn(4*((index) - 1) + 2) = complex(((2*double(bin_inp(3)) - 1)/sqrt(2)),((2*double(bin_inp(4)) - 1)/sqrt(2)));
%    txn(4*((index) - 1) + 3) = complex(((2*double(bin_inp(5)) - 1)/sqrt(2)),((2*double(bin_inp(6)) - 1)/sqrt(2)));
%    txn(4*((index) - 1) + 4) = complex(((2*double(bin_inp(7)) - 1)/sqrt(2)),((2*double(bin_inp(8)) - 1)/sqrt(2)));
    for index2 = 1:numel(bin_inp)
        if (bin_inp(index2) > 1)
            bin_inp(index2) = 1;
        end
        if (bin_inp(index2) < 0)
            bin_inp(index2) = 0;
        end
    end
    txn((floor((index - 1)/width) + 1),(rem((index-1),width) + 1)) = bi2de(bin_inp);
 end
